/*
 * Created on 26/07/2004
 *
 * Empresa: ACOL
 * Autor: Aldenir Barboza
 */
package com.acol.util;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class DownloadServlet extends HttpServlet {	

	public void service(HttpServletRequest request, 
						HttpServletResponse response) throws ServletException, IOException {
                        
		byte[] arrayDeBytes = (byte[])request.getAttribute("arrayDeBytes");
		String nomeArquivo = (String)request.getAttribute("nomeArquivo");

		response.setContentType("application/octet-stream");
		response.setContentLength(arrayDeBytes.length);
		response.setHeader("Content-disposition", "attachment;filename="+nomeArquivo);

		ServletOutputStream os = response.getOutputStream();
		os.write(arrayDeBytes, 0, arrayDeBytes.length);
		os.flush();
		os.close();
	}
}


